package com.xingongchang.baolebei.adapter;

import java.util.ArrayList;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;

import com.insthub.BeeFramework.adapter.BeeBaseAdapter;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.socialize.utils.Log;
import com.xingongchang.baolebei.ImageDisplay;
import com.xingongchang.baolebei.R;
import com.xingongchang.baolebei.protocol.CATEGORY;

public class HomeCategoryAdapter extends BeeBaseAdapter{
    ImageLoader imageLoader = ImageLoader.getInstance();
    DisplayImageOptions options;
    
    public class CategoryHolder extends BeeCellHolder
    {
        TextView goods_title,goods_desc;
        ImageView right_arrow,goods_img;
    }
    public HomeCategoryAdapter(Context c, ArrayList dataList,DisplayImageOptions options) {
        super(c, dataList);
        this.options=options;
		ImageView iamgeView = new ImageView(c);
		iamgeView.setScaleType(ScaleType.CENTER_CROP);
    }
    @Override
    protected BeeCellHolder createCellHolder(View cellView) {
        CategoryHolder holder = new CategoryHolder();
        holder.right_arrow = (ImageView)cellView.findViewById(R.id.right_arrow);
        holder.goods_img = (ImageView)cellView.findViewById(R.id.goods_img);
        holder.goods_title = (TextView) cellView.findViewById(R.id.goods_title);
        holder.goods_desc = (TextView) cellView.findViewById(R.id.goods_desc);
    
        return holder;
    }

    @Override
    protected View bindData(int position, View cellView, ViewGroup parent, BeeCellHolder beeHolder) {
        final CATEGORY categoryItem = (CATEGORY)dataList.get(position);
        final CategoryHolder holder = (CategoryHolder)beeHolder;
        holder.goods_title.setText(categoryItem.name);
        holder.goods_desc.setText(categoryItem.cat_desc);
        imageLoader.displayImage(categoryItem.showImg,  holder.goods_img, options);
        Log.v("abc",categoryItem.showImg);
        if (categoryItem.children.size() > 0)
        {
            holder.right_arrow.setVisibility(View.VISIBLE);
        }
        else
        {
            holder.right_arrow.setVisibility(View.GONE);
        }
        return cellView;
    }

    @Override
    public View createCellView() {
        View cellView = mInflater.inflate(R.layout.category_first_cell,null);
        return cellView;
    }
}